var planplus = {
  initialized: false,
  txt: "",
  
  onLoad: function() {
    // initialization code
    this.initialized = true;
    this.strings = document.getElementById("planplus-strings");
  },

  onMenuItemCommand: function(e) {
	var url = "http://www.planplus.rs/default.aspx?lang=&act=srcstr&src=" + escape(this.txt.trim());
	// initialize gBrowser var (global)
	getBrowser();
	// open new tab with url
	gBrowser.addTab(url);
  },

  getSelection: function(popupnode) {

	var nodeLocalName = popupnode.localName.toLowerCase();
	var selection = '';

	// Input or textarea
	if ((nodeLocalName == "textarea") || (nodeLocalName == "input" && popupnode.type == "text")) {

		selection = popupnode.value.substring(popupnode.selectionStart, popupnode.selectionEnd);

	// Image
	} else if (nodeLocalName == "img") {

		// Image title ?
		if (popupnode.title) {
			selection = popupnode.title;

		// Image alternative ?
		} else if (popupnode.alt) {
			selection = popupnode.alt;
		}

	// Link
	} else if (nodeLocalName == "a" && popupnode.hasAttribute("href") && (popupnode.textContent != "" || popupnode.hasAttribute("title"))) {

		// Link content ?
		if (popupnode.textContent != "") {
			selection = popupnode.textContent;

		// Link title ?
		} else if (popupnode.hasAttribute("title")) {
			selection = popupnode.getAttribute("title");
		}

	// Text selection.
	} else {
		selection = document.commandDispatcher.focusedWindow.getSelection().toString();
	}

	return selection;
},

  onToolbarButtonCommand: function(e) {
    // just reuse the function above.  you can change this, obviously!
    planplus.onMenuItemCommand(e);
  }
};

window.addEventListener("load", planplus.onLoad, false);
